﻿
Imports System.IO
Imports xhtmlctrl

Public Class inlineScript
    Inherits inlineResource

    Public Const defaultType As String = network.http.contentType.textjavascript

    Public Sub New(Optional ByVal buff As Stream = Nothing)
        MyBase.New(buff)
    End Sub

    Public Function addscript(ByVal type As String, ByVal name As String, ByVal content As String) As Boolean
        Return addresource(type, name, content)
    End Function

    Public Function addscript(ByVal name As String, ByVal content As String) As Boolean
        Return addscript(defaultType, name, content)
    End Function

    Public Shared Function registerScript(ByVal type As String, ByVal name As String, _
                                          ByVal content As String) As Boolean
        Return registerResource(type, name, content)
    End Function

    Public Shared Function registerScript(ByVal name As String, ByVal content As String) As Boolean
        Return registerScript(defaultType, name, content)
    End Function

    'since inlineScript will return with say, <script> tag,
    'and the type is defined in the tag, so can only input a type
    Public Shared Function registerScript(ByVal type As String, ByVal name As String, _
                                          ByVal sc As inlineScript) As Boolean
        Return registerResource(type, name, inlineResource.resourceContent(sc))
    End Function

    Public Shared Function registerScript(ByVal name As String, ByVal sc As inlineScript) As Boolean
        Return registerScript(defaultType, name, sc)
    End Function

    Public Function addRegisteredScript(ByVal type As String, ByVal name As String) As Boolean
        Return addRegisteredResource(type, name)
    End Function

    Public Function addRegisteredScript(ByVal name As String) As Boolean
        Return addRegisteredScript(defaultType, name)
    End Function

    Protected Overrides Function generateInstance() As xhtmlControl
        Return New script(output())
    End Function
End Class
